<template>
    <div class="container">
        <el-form ref="deptRef" :model="form" :rules="rules" label-width="200px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="项目名称">
                        <el-input v-model="form.subject" placeholder="请输入项目名称" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="密钥别称">
                        <el-input v-model="form.privateAlias" placeholder="请输入密钥别称" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="私钥密码">
                        <el-input v-model="form.keyPass" placeholder="请输入私钥密码" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="公共密码">
                        <el-input v-model="form.storePass" placeholder="请输入公共密码" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="证书生成路径">
                        <el-input v-model="form.licensePath" placeholder="请输入证书生成路径" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="密钥库存储路径">
                        <el-input v-model="form.privateKeysStorePath" placeholder="请输入密钥库存储路径" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="证书生效时间" prop="installTime">
                        <el-date-picker clearable
                                        v-model="form.issuedTime"
                                        type="datetime"
                                        value-format="YYYY-MM-DD HH:mm:ss"
                                        placeholder="选择证书生效时间"
                                        style="width: 100%;">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="证书失效时间" prop="expiryTime">
                        <el-date-picker clearable
                                        v-model="form.expiryTime"
                                        type="datetime"
                                        value-format="YYYY-MM-DD HH:mm:ss"
                                        placeholder="选择证书失效时间"
                                        style="width: 100%;">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="用户类型">
                        <el-input v-model="form.consumerType" placeholder="请输入用户类型" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="用户数量">
                        <el-input v-model="form.consumerAmount" placeholder="请输入用户数量" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="描述信息">
                        <el-input v-model="form.description" placehold er="请输入描述信息" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="系统硬件信息">
                        <el-input rows="6" type="textarea" v-model="form.modelJSON" placeholder="请输入系统硬件信息" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item>
                <el-button type="primary" @click="onSubmit" size="large">License 生成</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { generateLicense } from "@/api/system/license";
    import axios from "axios";
    
    const data = reactive({
        form: {}
    });

    const { queryParams, form, rules } = toRefs(data);

    // 表单重置
    function reset() {
        form.value = {
            subject: "MyLicenseDemo",
            privateAlias: "privateKey",
            keyPass: "private@2023",
            storePass: "public@2023",
            licensePath: "D:/license/license.lic",
            privateKeysStorePath: "D:/license/privateKey.keystore",
            issuedTime: "",
            expiryTime: "",
            consumerType: "User",
            consumerAmount: "1",
            description: "这是证书描述信息",
            licenseCheckModel: {},
            modelJSON: `{
                "ipAddress":["192.168.3.124"],
                "macAddress":["5C-80-B6-11-34-A6"],
                "cpuSerial":"BFEBFBFF000906EA",
                "mainBoardSerial":"MP1Q281J"
            }`
        }
    }

    const { proxy } = getCurrentInstance();

    // 提交按钮
    function onSubmit() {
        form.value.licenseCheckModel = JSON.parse(form.value.modelJSON);
        generateLicense(form.value).then(res => {
            if (res.code === 200) {
                proxy.$modal.msgSuccess("生成成功");
            } else {
                proxy.$modal.msgSuccess("生成失败");
            }
        });
    }

    reset();
</script>

<style scoped lang="scss">
    .container {
        padding: 50px;
        width: 1000px;
    }
</style>